/**
 * Created by lenovo on 2017/4/27.
 */
(function() {
	//页面的高度
	parent.$('#content').css('height', '1000px').css('width', '960px');

	//分页插件
	//  $('#pageToobar').Paging({pagesize:10,count:85,toolbar:true});

	//鼠标悬浮事件
	$('.shape').hover(function() {
		$(this).parent().find('.option').css('display', 'block');
	}, function() {
		$(this).parent().find('.option').css('display', 'none');
	})
	$('.option').hover(function() {
		$(this).css('display', 'block');
	}, function() {
		$(this).css('display', 'none');
	})

	/*下拉框 逻辑实现*/
	$('.btn-select').on('click', function() {
		var curSelect = $(this).find('span')[0];
		var oSelect = $(this).find('select')[0];
		var aOption = $(this)[0].getElementsByTagName('option');

		$(this).on('change', function() {
			var text1 = oSelect.options[oSelect.selectedIndex].text;
			curSelect.innerHTML = text1;
		})
	})

	/*下拉框 逻辑实现*/
	$('.btn-select1').on('click', function() {
		var curSelect = $(this).find('span')[0];
		var oSelect = $(this).find('select')[0];
		var aOption = $(this)[0].getElementsByTagName('option');

		$(this).on('change', function() {
			var text1 = oSelect.options[oSelect.selectedIndex].text;
			curSelect.innerHTML = text1;
		})
	})
	
	
	/*-----------------------------------*/
	
	$(document).on("mouseover mouseout", ".shape", function(event) {
		if(event.type == "mouseover") {
			$(this).parent().find('.option').css('display', 'block');

			//鼠标悬浮
		} else if(event.type == "mouseout") {
			//鼠标离开
			$(this).parent().find('.option').css('display', 'none');

		}
	})
	$(document).on("mouseover mouseout", ".option", function(event) {
		if(event.type == "mouseover") {
			$(this).css('display', 'block');

		} else if(event.type == "mouseout") {
			$(this).css('display', 'none');

		}
	})
/*------------------------------------------------------------------------------*/
	var html1 = $("#caption").html();

	function replace(str, item) {
		console.log(item.background)
		return str.replace(/\{province\}/, item.province||"（未知）")
			.replace(/\{equipCount\}/, item.equipCount)
			.replace(/\{userId\}/, item.userId)
			.replace(/\{nickname\}/, item.nickname)
			.replace(/\{numberCount\}/, item.numberCount)
			.replace(/\{postCount\}/, item.postCount)
			.replace(/\{followecount\}/, item.followeCount)
			.replace(/\{title\}/, item.title)
			.replace(/\{about\}/, item.about || "")
			.replace(/\{remark\}/, item.remark || "")
			.replace(/\{backgound\}/, item.background || "../image/default.jpg")
			

	}

	function renderUserList(data) {
		var director = "";
		var manger = "";
		var huiyuan = "";
		data.body.userList.forEach(function(item) {
			if(!item.title) {
				item.title = "";
			}
			if(item.title.indexOf("主理人") != -1) {
				director += replace($("#director").html(), item);

			} else if(item.title.indexOf("管理") != -1) {
				manger += replace($("#mannagerTmpl").html(), item);

			} else {
				huiyuan += replace($("#mannagerTmpl").html(), item);
			}
		})
		var html = html1 + director + manger + huiyuan;
		$(".ul_list").html(html);
	}
//	renderUserList(data);
	var clubId=config.sessionStroageGet("clubId");
	//用户管理接口
	function getUserList(page, size, callback) {
		$.getJSON(config.baseUrl + "/users/findUserListByOther", { page: page, count: size,clubId: clubId}, function(data) {
			callback(data);
		})
	}
	getUserList(1, 10, function(data) {
		renderUserList(data)
		$('#pageToobar').Paging({
			pagesize: 10,
			count: data.body.count,
			toolbar: true,
			callback: function(p, s) {
				getUserList(p, s, function(data) {
				renderUserList(data);
				})
			}
		});
	})
	
	/*=========================*/

	
	//修改权限配置
$(document).on("click",".xgqxpz",function(){
	var userId=$(this).parents(".userList").attr("data-userid");
	$.getJSON(config.baseUrl+"/users/updateCludMenber",{clubId:clubId*1,userId:userId*1},function(){
		
	})
})
//开除
$(document).on("click",".kc",function(){
	var userId=$(this).parents(".userList").attr("data-userid");
	
	$.getJSON(config.baseUrl+"/users/deleteUser",{clubId:clubId,userId:userId},function(){
		
	})
})
//
$(document).on("click",".swgly",function(){
	var userId=$(this).parents(".userList").attr("data-userid");
	
	$.getJSON(config.baseUrl+"",{clubId:clubId,userId:userId},function(){
		
	})
})
//移交主理人
$(document).on("click",".yjzlr",function(){
	var userId=$(this).parents(".userList").attr("data-userid");
	
	$.getJSON(config.baseUrl+"/users/updateCludAdmin",{clubId:clubId,userId:userId},function(){
		
	})
})


})($)
